package com.adcc.soundalarm.fx.alarm;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.awt.*;

/**
 * Created by ZHANG on 2017/3/31.
 */
public class AlarmView {

    private AlarmDialogController alarmDialogController;

    private Stage stageAlarm;

    private FXMLLoader loaderAlarm;

    public void start() throws Exception {
        if(loaderAlarm == null){
            loaderAlarm = new FXMLLoader(getClass().getResource("alarm_view.fxml"));
        }
        if(stageAlarm == null){
            stageAlarm = new Stage(StageStyle.UNDECORATED);
            Parent root = loaderAlarm.load();
            alarmDialogController = loaderAlarm.getController();
            alarmDialogController.buildEnvironment(stageAlarm);
            stageAlarm.setTitle("声音告警提示");
            stageAlarm.setScene(new Scene(root));
            location(stageAlarm);
            stageAlarm.show();
        }else {
            if(!stageAlarm.isShowing()){
                stageAlarm.show();
            }
        }
    }

    /**
     * 获取消息提示控制器
     * @return
     */
    public AlarmDialogController getAlarmDialogController() {
        return alarmDialogController;
    }

    private void location(Stage stage){
        Dimension dimenson = Toolkit.getDefaultToolkit().getScreenSize();
        stage.setWidth(521);
        stage.setHeight(365);
        stage.setX((dimenson.width - stage.getWidth() - 5));
        stage.setY((dimenson.height - stage.getHeight() - 40));
    }
}
